<?php
require_once ('Home/Controller/Controller.php ');
require_once ('Home/Model/IndexModel.php');
class IndexController extends Controller
{
	function __Construct()
	{
		parent::__Construct();
		//$this->mod = 'admin';
		//$this->model=new LoginModel();
	}
    function index(){
        $this->display();
    }
	function login(){
		$data=$_POST;
       // var_dump($data);
        if($data['username']=='admin')
            $flag=1;
		$model = new IndexModel();
		$result = $model->getLogin($data);
       // echo $flag;
		if($result)
		{

		    if($flag){
                session_start();
                $_SESSION['admin']=$data['username'];
                setcookie("admin",$data['username'],time()+3600*24);
                $_SESSION['password']=$data['password'];
		         $flag=0;
                echo '<h2 style="font-family:微软雅黑;color: #03c2f9">登录成功 ,您的身份为老师!<br/></h2>';
                echo '<a href="#">如果没有跳转，请点这里跳转</a>';
                header("refresh:3;url='admin.php'");
		    }
   			else{
                session_start();
                $_SESSION['username']=$data['username'];
                setcookie("username",$data['username'],time()+3600*24);
                $_SESSION['password']=$data['password'];
               echo  '<h2 style="font-family:微软雅黑;color: #03c2f9;">登录成功，您的身份为学生！<br/></h2>';
                echo '<a href="#">如果没有跳转，请点这里跳转</a>';
                header("refresh:3;url='index.php?c=student&m=student'");
            }
		}
		else
        {
            echo '<h2 style="font-family:微软雅黑;color:red">登录失败，请重新登录！<br/></h2>';
            header("refresh:3;url='index.php'");
        }
		$this->display();
	}
    function logout()
    {
        session_destroy();
        echo '<h2 style="font-family:微软雅黑;color: #03c2f9">注销成功!<br/></h2>';
        echo '<a href="index.php">如果没有跳转，请点这里跳转</a>';
        header("refresh:3;url='index.php'");
    }


	}